var message_height=0;//页头消息高度
var indexAchievementData;//成就json
var indexPedometerData;//运动json
var indexSleepData;//睡眠json
var indexDekaronData;//挑战json
var indexWeightData;//体重json
var memberFunctionList;//布局json
var loadIndexDataString="";
var logo_height=0;//logo高度


var curWwwPath=window.document.location.href; 
var pathName=window.document.location.pathname; 
var pos=curWwwPath.indexOf(pathName); 
var localhostPath=curWwwPath.substring(0,pos); 
var localIp=window.location.hostname;
//80ip地址
//var ip="203.195.214.80";
var ip="127.0.0.1";


function tmove(ev){
	var ibody=document.getElementById("main");
	
	ev = ev || window.event;  
    var point = {x:0,y:0};  
    point.x = event.touches[0].clientX;
    point.y = event.touches[0].clientY;
//	console.log(getScrollTop()+"滚动高");
//	console.log(startTop);
//	console.log(point.x+","+point.y);
	var scrollHeight=point.y-startpoint.y;
	
	if(getScrollTop()==0&&scrollHeight>0&&ttrue==true){
		var ajaxLoader=document.getElementById("ajaxLoader");
		if(getScrollTop()==0&&scrollHeight>120){
			ajaxLoader.style.display="block";
		}else{
			ajaxLoader.style.display="none";
		}
		ev.preventDefault();
		scrollHeight=scrollHeight/3;
		topValue=scrollHeight;
//		document.body.scrollTop=scrollHeight;
		ibody.style.top=scrollHeight+"px";
	}else{
		ttrue=false;
	}
}
var topValue=0;
var stopTimer=null;

var startpoint = {x:0,y:0};  
var endpoint = {x:0,y:0};  
var ttrue=false;
var a=0;
var startTop;
var i=0;
function tstart(ev){
	var ibody=document.getElementById("main");
	ibody.style.webkitTransition="none";
	var ajaxLoader=document.getElementById("ajaxLoader");
	ajaxLoader.style.display="none";
	startTop=ibody.style.top;
	if(getScrollTop()==0&&topValue==0){
		ttrue=true;
		ev = ev || window.event;  
		startpoint.x = event.touches[0].clientX;
		startpoint.y = event.touches[0].clientY;
	}else{
		ttrue=false;
	}
	console.log("开始："+startpoint.x+","+startpoint.y);
//	if(stopTimer!=null){
//		clearInterval(stopTimer);
//	}
}
function tend(ev){
	var ibody=document.getElementById("main");
	if(getScrollTop()==0){
		ev = ev || window.event;  
		endpoint.x = ev.changedTouches[0].clientX;
		endpoint.y = ev.changedTouches[0].clientY;
		console.log("结束："+endpoint.x+","+endpoint.y);
//		if(stopTimer==null)
//			stopTimer=setInterval(tstop, 10);
		
		if(topValue>40){
			setTimeout(clickRefresh, 1000);
			ibody.style.top ="45px";
			ibody.style.webkitTransition = "all 0.3s ease 0.1s";
//			setTimeout(hideLoader,500);
		}else{
			ibody.style.top ="0px";
			ibody.style.webkitTransition = "all 0.3s ease 0.1s";
		}
		topValue=0;
		
//		var ajaxLoader=document.getElementById("ajaxLoader");
//		ajaxLoader.style.display="none";
	}
	
}
function hideLoader(){
	var ajaxLoader=document.getElementById("ajaxLoader");
	ajaxLoader.style.display="none";
	var ajaxLoaderText=document.getElementById("ajaxLoaderText");
	ajaxLoaderText.style.display="block";
	
	var ibody=document.getElementById("main");
	ibody.style.top ="0px";
	ibody.style.webkitTransition = "all 0.5s ease 0.5s";
	
	setTimeout(hideLoaderText,500);
}

function hideLoaderText(){
	var ajaxLoaderText=document.getElementById("ajaxLoaderText");
	ajaxLoaderText.style.display="none";
}

function tstop(){
	var ibody=document.getElementById("main");
//	console.log(topValue);
	if(topValue<20){
		topValue-=5;
	}else{
		topValue-=20;
	}
	ibody.style.top=topValue+"px";
	if(topValue<=0&&stopTimer!=null){
		ibody.style.top="0px";
		clearInterval(stopTimer);
		stopTimer=null;
	}
	
}

//点击刷新
function clickRefresh(){
	i++;
	ajaxLoadIndexData();
}

function getScrollTop() {
	var scrollTop = 0;

	var name = navigator.platform;
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {
		if (document.documentElement
				&& document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scrollTop = document.body.scrollTop;
		}
	} else {
		if (document.documentElement && document.documentElement.scrollTop) {
			scrollTop = document.documentElement.scrollTop;
		} else if (document.body) {
			scrollTop = document.body.scrollTop;
		}
	}

	return scrollTop;
}

function hideWXOptionMenu(){
	try{
		wx.ready(function () {
			wx.hideOptionMenu();
		});
	}catch(err){
		
	}
}
var t1;
var load;
window.onload=function(){
	initAchievement();
	var user_achievements=document.getElementById("achieve");
	user_achievements.style.display = "block";
	load = document.getElementById("load");
	load.style.display="block";
	
	var message=document.getElementById("message");
	message.style.display = "none";
		
		
	wxcheckWXSignature();
	hideWXOptionMenu();
	
	var ibody=document.getElementById("main");
	ibody.style.top="0px";
	ibody.addEventListener("touchmove", tmove, false);
	ibody.addEventListener("touchstart", tstart, false);
	ibody.addEventListener("touchend", tend, false);
	
	window.addEventListener("pagehide", function(){
	    document.title="";
	    setTimeout(function(){},100); 
	}, false);
	
	var main=document.getElementById("main");
	ajaxLoadIndexData();
	
	var name = navigator.platform;
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {
		init_iphone_onclick();
	} else {
		init_html_onclick();
	}
	

	var pedometeropenId = document.getElementById("openId").value;
	var pedometermemberId = document.getElementById("memberId").value;

};

function connSocketIO(pedometermemberId,openId){

	var socket = io.connect(ip+":6380");

	socket.on('conn', function (data) {

	 var postdata = {

		   'c_id'   : pedometermemberId,     //用户id
		   'o_id'   : openId,     //openid

	 };

	 socket.emit('login', postdata);

	});
	
	socket.on('receive', function (data,fn) {

		showMessage(data.msg);

	});
	
	socket.on('receiveHomeUpload', function (data,fn) {
		upload(data.type);		

	});
}


function SetWinHeight(obj) {
	var win = obj;
	win.height = document.body.scrollHeight;
} 


//加载主页json数据
function ajaxLoadIndexData() {
	
	var ibody=document.getElementById("content_div");
	if(i==0){
		ibody.style.display="none";
	}
	var unionId=document.getElementById("unionId").value;
	var openId=document.getElementById("openId").value;
	var accountId = document.getElementById("accountId").value;
	var memberId = document.getElementById("memberId").value;
	var enterpriseId=document.getElementById("enterpriseId").value;
	
	var userType=document.getElementById("userType").value;
	
	var imgUrl="";
	var linkUrl="";
	
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
				if(json.length>0){
					//window.clearTimeout(t1);
					load.style.display = "none";
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					indexPedometerData=jsonData.indexPedometerData;
					indexAchievementData=jsonData.indexAchievementData;
//					indexSleepData=jsonData.indexSleepData;
					indexDekaronData=jsonData.indexDekaronData;
					indexWeightData=jsonData.indexWeightData;
					memberFunctionList=jsonData.memberFunctionList;
					ibody.style.display="block";
					document.getElementById("isFirstUse").value = jsonData.isFirstUse;
					if(i>0){
						hideLoader();
					}
					//判断是否为企业员工
					if(userType==2){
						document.getElementById("comIcon_div").style.display="none";
						document.getElementById("toolbar").style.display="none";
						logo_height=0;
					}
					else{
						logo_height=50;
						imgUrl=jsonData.enterpriseLogoUrl;
						linkUrl=jsonData.enterpriseIndex_url;
						//showEnterpriseLogo(enterpriseLogoUrl,enterpriseIndex_url);
						var enterpriseLogo=document.getElementById("enterpriseLogo");
						enterpriseLogo.src="http://weidong.lifesense.com/enterprise_logo/"+imgUrl;
						var enterpriseLogoBig=document.getElementById("enterpriseLogoBig");
						enterpriseLogoBig.src="http://weidong.lifesense.com/enterprise_logo/"+imgUrl;
						// document.getElementById("comIcon_div").style.display="block";
						if(document.getElementById("logoType").value == 1){
							document.getElementById("comIcon_div").style.display="none";
							document.getElementById("bigLogo").style.display="block";
						}else{
							document.getElementById("bigLogo").style.display="none";
							document.getElementById("comIcon_div").style.display="block";
						}	
						
						//if(userType==1 || userType==10){
							enterpriseLogo.onclick=function(){
								window.location.href='http://'+linkUrl;
							};
							enterpriseLogoBig.onclick=function(){
								window.location.href='http://'+linkUrl;
							};
						//}
					}
					if(memberFunctionList!=""&&memberFunctionList.length>0){
						closeMessage();
						initlayout2();
					}
					if(indexAchievementData!=null&&indexAchievementData!=""){
						if(isAchievement==0)
							initAchievement2();
					}

					if(indexDekaronData!=null&&indexDekaronData!=""){
						init(indexDekaronData);
					}
					if(indexWeightData!=null&&indexWeightData!=""){
						initWeight();
					}
					if(indexPedometerData!=null&&indexPedometerData!=""){
						initPedometer();
					}
					
					if(loadIndexDataString.indexOf("睡眠") >= 0){
						
						document.getElementById("countDevicePed").value = jsonData.countDevicePed;
						document.getElementById("deviceBindingState").value = jsonData.deviceBindingState;
						
						ajaxLoadIndexSleepData();
					}
				} 
			}
		}
	};
	var url = "/api/ajax/getDefaultData";
	xhr.open("post", url + "?openId="+openId+"&accountId="+accountId+"&memberId="+memberId+"&mathNum="+Math.random()+"&loadIndexDataString="+loadIndexDataString+"&enterpriseId="+enterpriseId ,true);
	xhr.send();
}

//加载首页睡眠的数据
function ajaxLoadIndexSleepData() {
	showLoader();
	initDrawSleepData();
	
	//loader图片显示
//	document.getElementById("mod-ajaxLoader").style.display = "block";
	document.getElementById("mod-ajaxLoader").addEventListener("click", mod_sleep_goSleepPage, false);
	
	var openId=document.getElementById("openId").value;
	var memberId = document.getElementById("memberId").value;
	
	var xhr = createXmlHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				var json = xhr.responseText;
				if(json.length>0){
					var jsonData = eval( "(" + json + ")" );//转换后的JSON对象
					indexSleepData = jsonData;
					if(indexSleepData!=null&&indexSleepData!=""){
						
						mod_sleep_initData();
						
						//loader图片隐藏
//						document.getElementById("mod-ajaxLoader").style.display = "none";
						hiddenLoader();
					}
				} 
			}
		}
	};
	var url = "/api/ajax/getSleepData";
	xhr.open("post", url + "?openId=" + openId + "&memberId=" + memberId + "&clear=" + new Date() * 1, true);
	xhr.send();
}






//获取浏览器内核 是否是奇葩- -
function getAndroidUA(){
	var uaName = navigator.userAgent;
	return uaName.substring(uaName.indexOf("; Android") - 1, uaName.indexOf("; Android"));
}

//初始化布局
function initlayout2(){
	var hidden_height=0;
	loadIndexDataString="";
	var hhh=memberFunctionList.length*150;
	for (var i = 0; i < memberFunctionList.length; i++) {
		var m=document.getElementById(memberFunctionList[i].url);
		if(memberFunctionList[i].open==1){
			loadIndexDataString+=memberFunctionList[i].name;
			m.style.display="block";
			m.style.position="absolute";
			m.style.top=(memberFunctionList[i].sequence-1)*150+90+message_height-hidden_height+"px";
		}else{
			m.style.display="none";
			hidden_height+=150;
		}
	}
	
	var container=document.getElementById("container");
	var h=0;
	if(getAndroidUA() == "U"){
		h=hhh+90-hidden_height;
		container.style.height=h-(90-logo_height)+"px";
	}else{
		h=hhh+90-hidden_height;
		container.style.height=h-(90-logo_height)+"px";
	}
	var toolbar=document.getElementById("toolbar");

	var name = navigator.platform;
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {

		toolbar.style.top=h+10+"px";
	} else {
		toolbar.style.top=h+10+"px";
	}
		
	
}

var layoutArray=new Array("mod-dekaron","mod-pedometer","mod-weight","mod-sleep");
var layoutValue=new Array(1,2,3,4);
var layoutShow=new Array(1,1,1,1);


//初始化布局
function initlayout(){
	var hidden_height=0;
	for (var i = 0; i < layoutArray.length; i++) {
		var m=document.getElementById(layoutArray[i]);
		if(layoutShow[i]==1){
			m.style.display="block";
			m.style.position="absolute";
			m.style.top=(layoutValue[i]-1)*150+90+message_height-hidden_height+"px";
		}else{
			m.style.display="none";
			hidden_height+=150;
		}
	}
	var container=document.getElementById("container");
	container.style.height=700-hidden_height+"px";
}
var isAchievement=0;

//初始化成就
function initAchievement(){
	
	if(imgurl!=""){
		var headImgUrl=imgurl;
		headImgUrl=headImgUrl.substring(0, (headImgUrl.length-1));
		headImgUrl+="64";
		document.getElementById("user_ico_header").src = headImgUrl;//头像
		isAchievement=1;
	}
	if(slevel!="")
		document.getElementById("user_level_img").src="/weixin/v1/img/level/level_lv"+slevel+".png";//等级

}

function initAchievement2(){
	if(indexAchievementData.imageUrl!=""){
		var headImgUrl=indexAchievementData.imageUrl;
		headImgUrl=headImgUrl.substring(0, (headImgUrl.length-1));
		headImgUrl+="64";
		document.getElementById("user_ico_header").src = headImgUrl;//头像
	}
	document.getElementById("user_name").innerHTML=indexAchievementData.name;//名字
	//document.getElementById("user_level_img").src=ctx+"/v2/img/level_lv"+indexAchievementData.level+".png";//等级
}

//获取XmlHttpRequest对象
function createXmlHttpRequest(){
	if(window.ActiveXObject){
	    return new ActiveXObject("Microsoft.XMLHTTP");
	}else if(window.XMLHttpRequest){
	    return new XMLHttpRequest();
	}
}

/**
 * 截取保留一位小数  (不四舍五入  小数点后为0取整数)  注：保留两位小数四舍五入之后
 * 
 */
function getDecimalOne(str) {
	var temp = str + "";
	var flag = parseFloat(str);
	if(temp.indexOf(".")>0){
		temp = flag.toFixed(2) + "";
		temp = temp.substring(0, temp.indexOf(".")+2);
	}
	return parseFloat(temp);
}

//点击事件监听
function init_iphone_onclick(){
	var message_close=document.getElementById("message-close");
	message_close.addEventListener("click", closeMessage, false);
	var user_achievements=document.getElementById("user_info");
	user_achievements.addEventListener("click", clickUserAchievements, false);
	var user_setting=document.getElementById("user_setting");
	user_setting.addEventListener("click", clickSetting, false);
}
function init_html_onclick(){
	var message_close=document.getElementById("message-close");
	message_close.addEventListener("click", closeMessage, false);
	var user_achievements=document.getElementById("user_info");
	user_achievements.addEventListener("click", clickUserAchievements, false);
	var user_setting=document.getElementById("user_setting");
	user_setting.addEventListener("click", clickSetting, false);

}

//点击设置
function clickSetting(){
	var userType=document.getElementById("userType").value;
	var enterpriseId=document.getElementById("enterpriseId").value;
	var openId=document.getElementById("openId").value;
	var memberId=document.getElementById("memberId").value;
	window.location.href="/page/setting?userType="+userType+"&&enterpriseId="+enterpriseId
	+"&&openId="+openId+"&&memberId="+memberId;
}


//点击跳转到成就
function clickUserAchievements(){
	document.title = "我的成就";
	var memberId=document.getElementById("memberId").value;
	var openId=document.getElementById("openId").value;
	window.location.href="/page/achievement?memberId="+memberId+"&openId="+openId;
}

//显示页头消息
function showMessage(message){
    var obj = document.getElementById("message");
    var contentObj = document.getElementById("message-content");

    if (obj != null){
        obj.style.display = "block";
        message_height=55;
        initlayout2();
    }

    if (contentObj != null){
        contentObj.innerHTML = message;
    }
}
//关闭页头消息
function closeMessage(){
    var obj = document.getElementById("message");
    if (obj != null){
        obj.style.display = "none";
        message_height=0;
        initlayout2();
    }
}

//点击布局
function clickLayout(){
	var memberId = document.getElementById("memberId").value;
	var openId = document.getElementById("openId").value;
	window.location.href=ctx+"/wechat/functionServlet?memberId="+memberId + "&openId=" + openId;
}

function showEnterpriseLogo(imgUrl,linkUrl){
	var enterpriseLogo=document.getElementById("enterpriseLogo");
	var logoUrl=document.getElementById("logoUrl").value;
	enterpriseLogo.src="http://weidong.lifesense.com/enterprise_logo/"+logoUrl;
}


//weight

function initWeight(){
	var weight_img=document.getElementById("mod-weight");
	var name = navigator.platform;
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {
		weight_img.addEventListener("click", clickWeightImg, false);
	} else {
		weight_img.addEventListener("click", clickWeightImg, false);
	}
	
	if(indexWeightData.deviceBindingState!=1){
		var weight=indexWeightData.weight;
		if(weight>0){
			var gg= indexWeightData.goalGap;
			if(indexWeightData.goalGap>0){
				gg="+"+indexWeightData.goalGap;
			}
			
			document.getElementById("weight_goal").innerHTML=weight;
			var wc=Math.abs(indexWeightData.weightChange);
			document.getElementById("weight_value").innerHTML=wc;
			document.getElementById("weight_goal_text").innerHTML=indexWeightData.weightChangeText;		
		}else{
			document.getElementById("weight_text").style.display="block";
			document.getElementById("weight_text2").style.display="none";
			document.getElementById("weight").style.display="none";
		}
	}else{
		document.getElementById("weight_text2").style.display="block";
		document.getElementById("weight_text").style.display="none";
		document.getElementById("weight").style.display="none";
		
		
	}
	
}
//点击图片跳转	
function clickWeightImg(){
	parent.document.title = "体重";
	var openId=parent.document.getElementById("openId").value;
	var memberId = parent.document.getElementById("memberId").value;
	if(indexWeightData.deviceBindingState==1){
		window.location.href=ctx+"/v3/weight/buy.html";
		parent.selectMenu(0);
	}else if(indexWeightData.deviceBindingState==2){
		parent.window.location.href=ctx+"/wechat/weightIndexv3?openId="+openId+"&memberId="+memberId+"&deviceBindingState=2";
	}else if(indexWeightData.deviceBindingState==4){
		parent.window.location.href=ctx+"/wechat/weightIndexv3?openId="+openId+"&memberId="+memberId+"&deviceBindingState=4";
	}else{
		parent.window.location.href=ctx+"/wechat/weightIndexv3?openId="+openId+"&memberId="+memberId;
	}
}

//sleep
//跳转至睡眠页面
function mod_sleep_goSleepPage(){
	parent.document.title = "睡眠";

	var memberId = document.getElementById("memberId").value;
	var openId = document.getElementById("openId").value;
	
	var countDevicePed = document.getElementById("countDevicePed").value; 
	var isFirstUse = document.getElementById("isFirstUse").value;
	var deviceBindingState = document.getElementById("deviceBindingState").value;

	if(deviceBindingState==1){
		window.location.href=ctx+"/v3/pedometer/buy.html";
	}else if(deviceBindingState==2){
		if(countDevicePed > 1 && isFirstUse == 0){
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=0";
		}else{
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=1";
		}
		
	}else if(deviceBindingState==4){
		if(countDevicePed > 1 && isFirstUse == 0){
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=0";
		}else{
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=1";	
		}
			
	}else{
		if(countDevicePed > 1 && isFirstUse == 0){
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=0";
		}else{
			window.location.href = "/page/sleep?openId="+openId+"&memberId="+memberId+"&countDevicePed="+countDevicePed+"&isFirstUse=1";
		}
		
	}
}


//填充数据
function mod_sleep_initData(){
	console.log(indexSleepData);
	var deviceBindingState=indexSleepData.deviceBindingState;
	if(deviceBindingState==1){
		document.getElementById("sleep").style.display="none";
		document.getElementById("sleep_no").style.display="block";
	}
	

	document.getElementById("mod-sleep").addEventListener("click", mod_sleep_goSleepPage, false);

	var data = indexSleepData;
	var daySleepM = data.sleepHoursM;
	var weekSleepM = data.weekSleep;
//		console.log("--------weekSleepM:" + weekSleepM);
	var sleepQuality = data.sleepQuality;
	if((daySleepM / 60 + "").split(".").length > 1){
		daySleepM = (daySleepM / 60 + "").split(".")[0] + "小时" + daySleepM % 60 + "分钟";
	}else{
		daySleepM = daySleepM > 0 ? daySleepM / 60 + "小时 0分钟" : "0小时";
	}
	
	if(weekSleepM){
		if((weekSleepM / 60 + "").split(".").length > 1){
			document.getElementById("mod-sleep-rTreeText").style.display = "block";
			weekSleepM = (weekSleepM / 60 + "").split(".")[0] + "小时" + weekSleepM % 60 + "分钟";	
		}else{
			weekSleepM = (weekSleepM / 60 + "").split(".")[0] + "小时";
		}
		
	}else{
		document.getElementById("mod-sleep-rTreeText").style.display = "none";
	}
	
	
	if(sleepQuality.length == 0){
		sleepQuality = "无";	
		document.getElementById("mod-sleep-dayQuality").style.color = "gray";
	}else{
		document.getElementById("mod-sleep-dayQuality").style.color = "#f7882d";
	}
	
	//console.log("daySleepM:" + daySleepM + "----weekSleepM:" + weekSleepM);
	document.getElementById("mod-sleep-dayHours").innerHTML = daySleepM;
	document.getElementById("mod-sleep-dayQuality").innerHTML = sleepQuality;
	document.getElementById("mod-sleep-weekHours").innerHTML = weekSleepM;
	
	mod_sleep_drawTree();
}

//绘制ajax返回后的睡眠数据树状图
function mod_sleep_drawTree(){
	var canvas = document.getElementById("mod-sleep-canvas");
	var treeTW = document.getElementById("mod-sleep-rTree").offsetWidth;
	if(indexSleepData.weekSleep){
		drawTreeToHomeSleep(treeTW * 2,75 * 2,canvas,"#f7882d","#f7882d","gray",indexSleepData);
	}
};

//绘制睡眠mod页面初始数据
function initDrawSleepData(){
	var data = {
		    "checkVersion": 0,
		    "countDevicePed": 1,
		    "deviceBindingState": 3,
		    "hLine": 0,
		    "nullTips": "无睡眠记录",
		    "sleepHoursM": 0,
		    "sleepQuality": "",
		    "weekSleep": 0,
		    "xLables": "一,二,三,四,五,六,日",
		    "yValues": ""
		};
	
	var canvas = document.getElementById("mod-sleep-canvas");
	var treeTW = document.getElementById("mod-sleep-rTree").offsetWidth;
	//默认数据
	drawTreeToHomeSleep(treeTW * 2,75 * 2,canvas,"#f7882d","#f7882d","gray",data);
}

//弹出加载图标层
function showLoader(){
	var alertWin = document.getElementById("mod-ajaxLoader");
	alertWin.style.display = "block";

	var mybg = document.createElement("div");
	mybg.setAttribute("id", "alert_bg");
	mybg.style.background = "black";
	mybg.style.width = "100%";
	mybg.style.height = 150 + "px";
	mybg.style.position = "absolute";
	mybg.style.overflow = "hidden";
	mybg.style.top = "0";
	mybg.style.left = "0";
	mybg.style.zIndex = "2500";
	mybg.style.opacity = "0.5";
	
	//var topWin = window.top.document.getElementById("iframe").contentWindow;
	var body = document.getElementById("mod-myBody");
	body.appendChild(mybg);
	body.style.overflow = "hidden";

}

//隐藏loader图标
function hiddenLoader() {
	var alertWin = document.getElementById("mod-ajaxLoader");
	var mybg = document.getElementById("alert_bg");
	alertWin && (alertWin.style.display = "none");
	if(mybg){
		//var topWin = window.top.document.getElementById("iframe").contentWindow;
		var body = document.getElementById("mod-myBody");
		body.removeChild(mybg);
	}
	
}

